const Hapi = require('hapi')
const config = require('./config')
const pluginHapiSwagger = require('./plugins/hapi-swagger')
const pluginHapiPagination=require('./plugins/hapi-pagination')
const hapiAuthJWT2 = require('hapi-auth-jwt2');
const pluginHapiAuthJWT2 = require('./plugins/hapi-auth-jwt2');
const router = require('./router');
const server = Hapi.server({
  port: config.port,
  host: config.host
})

const init = async () => {
  await server.register([...pluginHapiSwagger,
    pluginHapiPagination
  ])
  await server.register([
     hapiAuthJWT2
   ])
   pluginHapiAuthJWT2(server)
  server.route(router)
  await server.start();
  console.log(`Server running at: ${server.info.uri}`);
};

process.on('unhandledRejection', (err) => {

  console.log(err);
  process.exit(1);
});

init()
